﻿using System.Linq;
using Complaint.Models.Dtos;

namespace Complaint.Repositories
{
    public class ResponseRepository : BaseRepository<Response>, IRepository<Response>
    {
        #region IRepository<Response> Members

        public void Create(Response dto)
        {
            ObjectContext.AddToResponse(dto);
            Update(dto);
        }

        public IQueryable<Response> FindAll()
        {
            return ObjectContext.Response;
        }

        public Response FindById(int id)
        {
            return FindAll().FirstOrDefault(r => r.ResponseID == id);
        }

        public IQueryable<Response> FindByName(string name)
        {
            return from response in FindAll()
                   where response.Title == name
                   select response;
        }

        #endregion

        public IQueryable<Response> FindByComplaint(int id)
        {
            return from response in FindAll()
                   where response.Complaint.ComplaintID == id
                   select response;
        }

        public IQueryable<Response> FindByRef(string orgRef)
        {
            return from response in FindAll()
                   where response.OrganisationRef == orgRef
                   select response;
        }
    }
}